package com.hdu.controller;


import com.hdu.service.TaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import static com.hdu.delayTask.SendMessageDelayTask.TASK_NAME;
import static com.hdu.delayTask.SendMessageDelayTask.createMessage;

@RestController
public class TestController {

    private static final Logger log = LoggerFactory.getLogger(TestController.class);
    private final TaskService taskService;

    public TestController(TaskService taskService) {
        this.taskService = taskService;
    }


    @GetMapping("/test/{minute}")
    public String test(@PathVariable int minute) {
        log.info("设置一个延迟任务, {}分钟后执行", minute);
        // 获得 minute 后的时间戳
        long executeTime = System.currentTimeMillis() + 1000L * 60 * minute;
        // 添加一个延迟任务
        taskService.addTask(
                TASK_NAME,
                1,
                createMessage("qyh", "zwd", "哈哈哈"),
                executeTime
        );
        return "ok";
    }
}
